<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
	<head>
		<title>流程定义编辑</title>
		<%@ include file="/commons/meta.jsp"%>
		<script language=javascript src="${ctx}/scripts/date/wpCalendar.js"></script>
		<script language=javascript src="${ctx}/scripts/home/prototype.js"></script>
		<script language="JavaScript" src="${ctx}/scripts/home/common.js"></script>
		<script type="text/javascript">
		    function winclose(){
			    if(isWinClose()){
			      validate();
			    }else{
			       window.close();
			    }
			}
			/**验证和提交表单*/
			function validate(){
				var msg = "";
				
				var name = document.ProcessDefinitionForm.name.value;
				if(name == "") {msg += "--流程名称不能为空;\n";} else if(name.length > 20){msg += "--流程名称长度不能超过20个字符;\n";}

				var processXml = getProcessXml();
				getProcessImage();
				//alert(processXml);
				if(processXml == "") {msg += "--流程图不能为空;\n";}
				
				if(msg != "") {alert(msg);} else {document.ProcessDefinitionForm.submit();}

			}
			
			/**提供给FLEX通讯，由FLEX调用;用来获取部门和用户。*/
			function getContextPath(){
  				//return "${ctx}/pages/workflow/testWorkflow.jsp";
  				return "${ctx}/ProcessDefinitionAction.do?method=getDeps&depId=";
  			}
  			
  			/**提供给FLEX通讯，由FLEX调用；用来获取流程XML*/
  			function getProcessXmlFromJava(){
  				return document.ProcessDefinitionForm.processXml.value;
  			}
  
            /**和FLEX通讯，调用FLEX方法获取流程XML*/
  			function getProcessXml(){
  				var xml = document.getElementById("IwWorkFlow").getProcessXml();
  				document.ProcessDefinitionForm.processXml.value = xml;
  				return xml;
  			}
  			
  			/**和FLEX通讯，调用FLEX方法获取流程截图*/
  			function getProcessImage(){
  				var xml = document.getElementById("IwWorkFlow").getProcessImage();
  				document.ProcessDefinitionForm.processImage.value = xml;
  			}
  			
  			/**由大专业触发,联动改变小专业*/
  			function setSmallProfe(val){
  				if(val == null) return;
  				var url = "${ctx}/ProcessDefinitionAction.do";
  				var pars = "method=getSmallprofeIds&pid=" + val;
  				
  				new Ajax.Request(     
				url,      
				{     
					method: 'post',      
					parameters: pars,      
					onSuccess: setCmProfessionalId     
				}); 
  			}
  			
  			/**回调函数*/
  			function setCmProfessionalId(XMLHttpReq){
  				 var smProfeId = XMLHttpReq.responseXML.getElementsByTagName("id");
  				 var smProfeName = XMLHttpReq.responseXML.getElementsByTagName("name");
  				 
  				 var len = smProfeId.length;
			 	 var name = "";
			  	 var id   = "";
			 	 var op   ="";
			 	 var tem  = document.getElementById("smProfessionalId");
			 	 document.getElementById("smProfessionalId").options.length = 0;
			 	 
			 	 for(var i=0; i<len ; i++){
			 		 id = smProfeId[i].firstChild.nodeValue;
			 		 name = smProfeName[i].firstChild.nodeValue;
			 		 op = new Option(name, id); 
			 		 tem.add(op);
			 	 }
  			}
		</script>
	
	</head>
	<body scroll="yes">
		<div class="albox">
			<!--统一信息头部开始-->
			<ul>
				<li>
					<img src="${templateVo.styleImagePath}/list9.gif" />
				</li>
				<li style="width: 99%">
					<table width="100%" border="0" cellspacing="0" cellpadding="0"
						align="center" class="albox1">
						<tr>
							<td width="2%" align="right" height="31">
								<img src="${templateVo.styleImagePath}/ico_clock3.gif" />
							</td>
							<td width="4%">
								<a href="javascript:void(validate())">保存</a>
							</td>
							<td width="2%">
								<img src="${templateVo.styleImagePath}/ico_clock1.gif" />
							</td>
							<td width="4%">
								<a href="javascript:void(winclose())">返回</a>
							</td>
							<td width="84%"></td>
						</tr>
					</table>
				</li>
				<li style="float: right;">
					<img src="${templateVo.styleImagePath}/list10.gif" />
				</li>
			</ul>
			<!--统一信息头部结束-->
		</div>

		<div style="width: 100%; float: left;">
			<table width="98%" border="0" cellspacing="0" cellpadding="0"
				align="center">
				<tr>
					<td class="edittit" align="center">
						流程定义编辑
					</td>
				</tr>
				<tr>
					<td align="center">
						&nbsp;
					</td>
				</tr>
			</table>
			<html:form action="/ProcessDefinitionAction.do" styleClass="form" method="post">
				<input type="hidden" name="method" value="save" />
				<html:hidden property="id" />
				<html:hidden property="processXml"/>
				<html:hidden property="processImage"/>
				<table width="98%" border="1" cellspacing="1" cellpadding="2">
				    
					<tr class=tr001>
						<td width=12% class='text12_1' align=right bgcolor='#F7F7F7'>流程名称：</td>
						<td bgcolor='#Ffffff'><html:text property="name" styleClass="text"/><font color=red>(*)</font></td>
						
						<td width=12% class='text12_1' align=right bgcolor='#F7F7F7'>类型：</td>
						<td bgcolor='#Ffffff'>
							<html:select property="type" style="text">
								<html:option value="0">工单派发流程</html:option>
								<html:option value="1">审批流程</html:option>
							</html:select>
						</td>
					</tr>
					<tr>
						<td width=12% class='text12_1' align=right bgcolor='#F7F7F7'>简要说明：</td>
						<td bgcolor='#Ffffff' colspan="9"><html:text property="remark" styleClass="text" size="100"/></td>
					</tr>
					
				</table>
			</html:form>
			
			<div style="width:98%; height:800px;">			
  				<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
					id="IwWorkFlow" width="100%" height="100%"
					codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
				<param name="movie" value="${ctx }/workflow/IwWorkFlow.swf" />
				<param name="quality" value="high" />
				<param name="bgcolor" value="#869ca7" />
				<param name="allowScriptAccess" value="sameDomain" />
				<embed src="${ctx }/workflow/IwWorkFlow.swf" quality="high" bgcolor="#869ca7"
					width="100%" height="100%" name="IwWorkFlow" align="middle"
					play="true"
					loop="false"
					quality="high"
					allowScriptAccess="sameDomain"
					type="application/x-shockwave-flash"
					pluginspage="http://www.adobe.com/go/getflashplayer">
				</embed>
				</object>			
			</div>
			
		</div>
	</body>
</html>
